//
//  XSJMyHeadView.m
//  ZF
//
//  Created by apple on 2019/3/8.
//  Copyright © 2019 hyy. All rights reserved.
//

#import "XSJMyHeadView.h"
#import "UIImageView+WebCache.h"

@interface XSJMyHeadView()

@property (nonatomic, strong) UIImageView* bjIconView;
@property (nonatomic, strong) UIButton* setUpButton;
@property (nonatomic, strong) UIView* bgView;
@property (nonatomic, strong) UIImageView* nextView;
@property (nonatomic, strong) UIImageView* iconView;
@property (nonatomic, strong) UILabel* nameLabel;
@property (nonatomic, strong) UIImageView* gradeBGView;
@property (nonatomic, strong) UIImageView* gradeView;
@property (nonatomic, strong) UILabel* gradeLabel;
@property (nonatomic, strong) UIImageView* levelView;
@property (nonatomic, strong) UILabel* levelLabel;
@property (nonatomic, strong) UIButton* friendButton;
@property (nonatomic, strong) UIButton* followButton;
@property (nonatomic, strong) UIButton* fansButton;
@property (nonatomic, strong) UIButton* worksButton;

@end

@implementation XSJMyHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    self.backgroundColor = ColorHex(0xf3f5f7);
    [self addSubview:self.bjIconView];
    [self addSubview:self.setUpButton];
    [self addSubview:self.bgView];
    [self addSubview:self.nextView];
    [self addSubview:self.iconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.gradeBGView];
    [self addSubview:self.gradeView];
    [self addSubview:self.gradeLabel];
    [self addSubview:self.levelView];
    [self addSubview:self.levelLabel];
    [self addSubview:self.friendButton];
    [self addSubview:self.followButton];
    [self addSubview:self.fansButton];
    [self addSubview:self.worksButton];
    
    [_bjIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(230);
    }];
    
    [_setUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_bjIconView.mas_top).offset(30);
        make.right.mas_equalTo(-50);
    }];
    
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_bjIconView.mas_top).offset(70);
        make.centerX.equalTo(self);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(165);
    }];
    
    [_nextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_bgView.mas_right).offset(-15);
        make.top.equalTo(self->_bgView.mas_top).offset(50);
    }];
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_bgView.mas_left).offset(13);
        make.top.equalTo(self->_bgView.mas_top).offset(24);
        make.width.height.mas_equalTo(69);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_iconView.mas_right).offset(15);
        make.top.equalTo(self->_bgView.mas_top).offset(35);
    }];
    
    [_gradeBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_iconView.mas_right).offset(15);
        make.top.equalTo(self->_nameLabel.mas_bottom).offset(10);
    }];
    
    [_gradeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_gradeBGView.mas_left).offset(3);
        make.centerY.equalTo(self->_gradeBGView);
    }];
    
    [_gradeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_gradeView.mas_right).offset(0);
        make.centerY.equalTo(self->_gradeBGView);
    }];
    
    [_levelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_gradeBGView.mas_right).offset(10);
        make.centerY.equalTo(self->_gradeView);
    }];
    
    [_levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self->_levelView);
        make.centerX.equalTo(self->_levelView).offset(0);
    }];
    
    [_friendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_bgView.mas_left).offset(18);
        make.bottom.equalTo(self->_bgView.mas_bottom).offset(-10);
    }];
    
    [_followButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_friendButton.mas_right).offset(60);
        make.bottom.equalTo(self->_bgView.mas_bottom).offset(-10);
    }];
    
    [_fansButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_followButton.mas_right).offset(60);
        make.bottom.equalTo(self->_bgView.mas_bottom).offset(-10);
    }];
    
    [_worksButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_fansButton.mas_right).offset(60);
        make.bottom.equalTo(self->_bgView.mas_bottom).offset(-10);
    }];
}


//-(void)setUserInfo:(UserInfoModel *)userInfo
//{
//    _userInfo = userInfo;
//    //显示头像
//    if (!kStringIsEmpty(_userInfo.picture))
//    {
//        [_iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.picture]];
//    }
//
//    _idLabel.text = [NSString stringWithFormat:@"ID:%@",_userInfo.ID];
//    _gradeLabel.text = [NSString stringWithFormat:@"    VIP%@",_userInfo.vipLevel];
//    _nameLabel.text = _userInfo.name;
//    _autographLabel.text = _userInfo.style;
//    _regionLabel.text = _userInfo.location;
//    _levelLabel.text = [NSString stringWithFormat:@"%ld",_userInfo.level];
//    //等级
//    _levelView.image = [Tool getLevelImage:_userInfo.level];
//
//    [_fansButton setTitle:[NSString stringWithFormat:@"     粉丝\n       %@",_userInfo.fan] forState:UIControlStateNormal];
//    [_followButton setTitle:[NSString stringWithFormat:@"关注\n  %@",_userInfo.notice] forState:UIControlStateNormal];
//    [_kbiButton setTitle:[NSString stringWithFormat:@"K币\n%@",_userInfo.money] forState:UIControlStateNormal];
//}

-(void)friendButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:1];
    }
}

-(void)fansButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:2];
    }
}

-(void)followButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:3];
    }
}

-(void)worksButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:4];
    }
}

-(void)setUpButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:5];
    }
}

- (UIImageView *)bjIconView {
    if (_bjIconView == nil) {
        _bjIconView = [[UIImageView alloc] init];
        _bjIconView.image = [UIImage imageNamed:@"MyBJ"];
    }
    return _bjIconView;
}

- (UIButton *)setUpButton {
    if (_setUpButton == nil) {
        _setUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_setUpButton setImage:[UIImage imageNamed:@"installed"] forState:UIControlStateNormal];
        [_setUpButton addTarget:self action:@selector(setUpButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _setUpButton;
}

-(UIView *)bgView
{
    if(_bgView==nil)
    {
        _bgView = [[UIView alloc]initWithFrame:CGRectZero];
        _bgView.backgroundColor = ColorHex(0xffffff);
        _bgView.layer.cornerRadius = 5.0f;
    }
    return _bgView;
}

- (UIImageView *)nextView {
    if (_nextView == nil) {
        _nextView = [[UIImageView alloc] init];
        _nextView.image = [UIImage imageNamed:@"next"];
        //下一步点击事件
        _nextView.userInteractionEnabled = YES;
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [_nextView addGestureRecognizer:singleTap];
    }
    return _nextView;
}

- (void)handleSingleTap:(UITouch *)touch
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(XSJMyHeadViewDidClick:)])
    {
        [self.delegate XSJMyHeadViewDidClick:1];
    }
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc] init];
        _iconView.image = [UIImage imageNamed:@"missportrait"];
        _iconView.layer.cornerRadius = 35.0f;
        _iconView.clipsToBounds = YES;
        //头像点击事件
        _iconView.userInteractionEnabled = YES;
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [_iconView addGestureRecognizer:singleTap];
    }
    return _iconView;
}

- (UILabel *)nameLabel {
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = ColorHex(0x222222);
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.text = @"陈宝宝老师";
    }
    return _nameLabel;
}

- (UIImageView *)gradeBGView {
    if (_gradeBGView == nil) {
        _gradeBGView = [[UIImageView alloc] init];
        _gradeBGView.image = [UIImage imageNamed:@"miss01"];
    }
    return _gradeBGView;
}

- (UIImageView *)gradeView {
    if (_gradeView == nil) {
        _gradeView = [[UIImageView alloc] init];
        _gradeView.image = [UIImage imageNamed:@"miss"];
    }
    return _gradeView;
}

- (UILabel *)gradeLabel {
    if (_gradeLabel == nil) {
        _gradeLabel = [[UILabel alloc] init];
        _gradeLabel.textColor = ColorHex(0xFFFFFF);
        _gradeLabel.font = [UIFont systemFontOfSize:8];
        _gradeLabel.text = @"30";
    }
    return _gradeLabel;
}

- (UIImageView *)levelView {
    if (_levelView == nil) {
        _levelView = [[UIImageView alloc] init];
        _levelView.image = [UIImage imageNamed:@"lv"];
    }
    return _levelView;
}

- (UILabel *)levelLabel {
    if (_levelLabel == nil) {
        _levelLabel = [[UILabel alloc] init];
        _levelLabel.textColor = ColorHex(0xFFFFFF);
        _levelLabel.font = [UIFont systemFontOfSize:8];
        _levelLabel.text = @"5";
    }
    return _levelLabel;
}

- (UIButton *)friendButton {
    if (_friendButton == nil) {
        _friendButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_friendButton setTitle:@"12312\n  好友" forState:UIControlStateNormal];
        _friendButton.titleLabel.lineBreakMode = 0;
        [_friendButton setTitleColor:ColorHex(0x282828) forState:UIControlStateNormal];
        _friendButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_friendButton addTarget:self action:@selector(friendButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _friendButton;
}

- (UIButton *)followButton {
    if (_followButton == nil) {
        _followButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followButton setTitle:@"888\n关注" forState:UIControlStateNormal];
        _followButton.titleLabel.lineBreakMode = 0;
        [_followButton setTitleColor:ColorHex(0x282828) forState:UIControlStateNormal];
        _followButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_followButton addTarget:self action:@selector(followButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _followButton;
}

- (UIButton *)fansButton {
    if (_fansButton == nil) {
        _fansButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_fansButton setTitle:@"999\n粉丝" forState:UIControlStateNormal];
        _fansButton.titleLabel.lineBreakMode = 0;
        [_fansButton setTitleColor:ColorHex(0x282828) forState:UIControlStateNormal];
        _fansButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_fansButton addTarget:self action:@selector(fansButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _fansButton;
}

- (UIButton *)worksButton {
    if (_worksButton == nil) {
        _worksButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_worksButton setTitle:@" 15\n作品" forState:UIControlStateNormal];
        _worksButton.titleLabel.lineBreakMode = 0;
        [_worksButton setTitleColor:ColorHex(0x282828) forState:UIControlStateNormal];
        _worksButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_worksButton addTarget:self action:@selector(worksButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _worksButton;
}



@end
